package
{
	import laya.device.motion.Gyroscope;
	import laya.device.motion.RotationInfo;
	import laya.display.Sprite;
	import laya.display.Stage;
	import laya.display.Text;
	import laya.events.Event;
	import laya.utils.Browser;
	import laya.utils.Handler;
	import laya.webgl.WebGL;
	
	import ui.EffectAnimationUI;
	import ui.MaskDemoUI;

	public class Main 
	{
		private var _txtSample:TextSample;
		private var _compUrl:String = "res/atlas/comp.atlas";
		private var _resUrl:String = "res/atlas/res.atlas";
		private var _roleUrlAtlas:String = "res/atlas/role.atlas";
		public function Main()
		{
			Laya.init(720,1280,WebGL);
			Laya.stage.alignH = Stage.ALIGN_CENTER;
			Laya.stage.alignV = Stage.ALIGN_MIDDLE;
			Laya.stage.bgColor = "#cccccc";
			Laya.stage.scaleMode = Stage.SCALE_FIXED_AUTO;
			Laya.stage.screenMode = Stage.SCREEN_VERTICAL;
			Laya.loader.load([
				_resUrl,
				_compUrl,
				_roleUrlAtlas
			],Handler.create(this,onResLoaded)); //预加载资源
			
			Gyroscope.instance.on(Event.CHANGE, this, onDeviceorientation);
		}
		
		private function onDeviceorientation(absolute:Boolean, rotationInfo:RotationInfo):void
		{
			// TODO Auto Generated method stub
			Laya.stage.scaleMode = Stage.SCALE_FIXED_AUTO;
			if(Math.abs(rotationInfo.beta)<=12)
			{
				//横屏
				//Laya.stage.scaleMode = Stage.SCALE_FIXED_WIDTH;
				Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;
			}else
			{
				//竖屏
				//Laya.stage.scaleMode = Stage.SCALE_FIXED_HEIGHT;
				Laya.stage.screenMode = Stage.SCREEN_VERTICAL;
			}
		}
		private var count:int = 0;
		private function onResize(e:Event=null):void
		{
			if(Browser.width>Browser.height)
			{
				//横屏
				Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;
			}else
			{
				//竖屏
				Laya.stage.screenMode = Stage.SCREEN_VERTICAL;
			}
			count++;
			
		}
		
		private function onResLoaded(res:*):void
		{
			//res  = Laya.loader.getRes(_resUrl);
			trace(" ... ",res);
			//_txtSample = new TextSample();
			//var bmpSample:BitmapSample = new BitmapSample();			
			//var uiDemo:MaskDemoUI = new MaskDemoUI();
			//Laya.stage.addChild(uiDemo);
			
			//var skillCd:SkillCDMaskSample = new SkillCDMaskSample();
			
			/*var sp:Sprite = new Sprite();
			Laya.stage.addChild(sp);
			sp.alpha = 0.8;			
			sp.graphics.drawRect(50,50,50,50,"#ff0000");
			
			
			var sp1:Sprite = new Sprite();
			sp1.alpha = 0.5;
			//Laya.stage.addChild(sp1);
			//画扇形
			//sp1.graphics.drawPie(75,75,40,0,360,"#ffff00");
			//sp.mask = sp1;
			*/
			
			var aniSample:AnimationSample = new AnimationSample();
			
			//测试动画模板功能
			//var eff:EffectAnimationUI = new EffectAnimationUI();
			//Laya.stage.addChild(eff);
			
			//测试设备旋转
			//var gyro:Gyroscope_Sample = new Gyroscope_Sample();
			
			
		}

	}
}